<!DOCTYPE html>
<html>
<head>
<title>查看订单</title>
#include("../include/common.html")
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox float-e-margins">
            <!-- <div class="ibox-title">
                <h5>查看订单</h5>
            </div> -->
            <input type="hidden" id="orderId" value="#(order.id)">
           <div class="tabs-container form-line">
               <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1">订单信息</a></li>
                    <li class=""><a data-toggle="tab" href="#tab-2">商品信息</a></li>
                    <li class=""><a data-toggle="tab" href="#tab-3">包裹信息</a></li>
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane active">
                        <div class="panel-body form-horizontal">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">&nbsp;</label>
                                <div class="col-sm-8">
                                    #if(order.statusKey=="PENDING_SHIPMENT") <input type="button" id="shippingButton" class="btn btn-w-m btn-primary" value="发 货"  /> #end
                                </div>
                            </div>
	                        <div class="form-group">
	                            <label class="col-sm-3 control-label">编号：</label>
	                            <div class="col-sm-3">
	                                #(order.sn)
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label class="col-sm-3 control-label">创建日期：</label>
	                            <div class="col-sm-3">
	                                #date(order.createDate,"yyyy-MM-dd")
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label class="col-sm-3 control-label">状态：</label>
	                            <div class="col-sm-3">
	                                #(order.statusName)
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label class="col-sm-3 control-label">金额：</label>
	                            <div class="col-sm-3">
	                                                                                                ￥#(order.amount)
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label class="col-sm-3 control-label">商品数量：</label>
	                            <div class="col-sm-3">
	                                #(order.totalQuantity)
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label class="col-sm-3 control-label">支付方式：</label>
	                            <div class="col-sm-3">
	                                #if(order.paymentMethod??)#(order.paymentMethodName) #else - #end
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label class="col-sm-3 control-label">收货人：</label>
	                            <div class="col-sm-3">
	                                		收货人:#(order.consignee)<br>
                                        	手机号码:#(order.phone)<br>
                                        	地址:#(order.province);#(order.city);#(order.district);#(order.address)<br>
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label class="col-sm-3 control-label">附言：</label>
	                            <div class="col-sm-3">
	                                #(order.memo)
	                            </div>
	                        </div>
                    </div>
                </div>
                <div id="tab-2" class="tab-pane">
                    <div class="panel-body form-horizontal">
                        <div class="form-group">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>商品条码</th>
                                        <th>商品图片</th>
						                <th>商品名称</th>
						                <th>商品价格</th>
						                <th>数量</th>
						                <th>小计</th>
                                     </tr>
                                 </thead>
                                 <tbody>
                                     #for(orderItem : order.orderItems)
				                    <tr>
					                    <td>#(orderItem.sn)</td>
					                    <td><img src="#(imageUrl(orderItem.image))" height="50"/></td>
					                    <td>#(orderItem.name)</td>
					                    <td>￥#(orderItem.price)</td>
					                    <td>#(orderItem.quantity)</td>
					                    <td>￥#(orderItem.subtotal)</td>
				                    </tr>
				                    #end
                                 </tbody>
                             </table>
                         </div>
                     </div>
                </div>
                <div id="tab-3" class="tab-pane">
                <div class="panel-body form-horizontal">
                
                <div class="form-group">
	                            <label class="col-sm-3 control-label">&nbsp;</label>
	                            <div class="col-sm-3">
	                                <button type="button" class="btn btn-primary" style="margin-top: 20px;" id="addPack" val="#(order.id)">添加包裹</button>
	                            </div>
	                        </div>
                
                
                <div class="form-group">
                      <div class="row">
                      		<label class="col-sm-3 control-label">包裹信息：</label>
                            <div class="col-sm-9">
                            	<table class="table table-bordered">
		                            <thead>
		                                <tr>
		                                    <th>快递单号</th>
		                                    <th>快递公司名称</th>
		                                    <th>打包照片</th>
		                                    <th>包裹预估重量</th>
		                                    <th>操作</th>
		                                </tr>
		                            </thead>
		                            <tbody>
		                            	#if(order.packs??)
		                            	#for(pack : order.packs)
		                                <tr id="packTr_#(pack.id)">
		                                    <td>#(pack.expressNumber)&nbsp;&nbsp;&nbsp;<input type="button" val="#(pack.id)" class="btn btn-w-m btn-primary trafficButton" value="查看物流"/>
		                                    </td>
		                                    <td>#(pack.expressCode)</td>
		                                    <td><img src="#(imageUrl(pack.photo))" height="50"/></td>
		                                    <td>#(pack.weight)</td>
		                                    <td><button type="button" class="btn btn-danger packdelete" val="#(pack.id)" style="margin-top: 20px;">删除</button></td>
		                                </tr>
		                                <tr>
		                                	<td colspan="5">
			                                	<table class="table table-bordered">
						                            <thead>
						                                <tr>
						                                    <th>商品ID</th>
						                                    <th>商品条码</th>
						                                    <th>商品名称</th>
						                                    <th>商品图片</th>
						                                    <th>商品数量</th>
						                                </tr>
						                            </thead>
						                            <tbody>
						                            	#for(packProduct : pack.packProducts)
						                                <tr>
						                                    <td>#(packProduct.productId)</td>
						                                    <td>#(packProduct.sn)</td>
						                                    <td>#(packProduct.name)</td>
						                                    <td><img src="#(imageUrl(packProduct.image))" height="50"/></td>
						                                    <td>#(packProduct.quantity)</td>
						                                </tr>
						                                #end
						                            </tbody>
						                        </table>
		                                	</td>
		                                </tr>
		                                #end
		                                #end
		                            </tbody>
		                        </table>
                            </div>
                       </div>
                      </div>
                
                
                </div>
                </div>
                
                </div>
                <div class="modal-footer col-sm-3 col-sm-offset-2">
                    <button type="button" class="btn btn-w-m btn-default" onclick="history.back(); return false;">返回</button>
                </div>
            </div>
        </div>
    </div>
    
    <!-- model -->
  <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModel" class="modal fade">
  <div class="modal-dialog" role="document">
  <div class="modal-content">
  </div>
  </div>
  </div>
    
</body>
</html>
<script type="text/javascript">
$().ready(function() {

    var $completeForm = $("#completeForm");
    var $shippingForm = $("#shippingForm");
    var $completeButton = $("#completeButton");
    var $shippingButton = $("#shippingButton");
    
    // 发货
    $shippingButton.click(function(){
		var orderId = $("#orderId").val();
        if(confirm("确定要发货吗?")){
        	$.ajax({
    	        url: "shipping",
    	        type: "POST",
    	        data: {"id":orderId},
    	        dataType: "json",
    	        cache: false,
    	        success: function(response) {
    	        	if (response.type == "success") {
    	        		location.reload();
    	            }else{
    	                swal({title:'', text:response.msg,icon: 'error'});
    	            }
    	        }
    	    });
        }
    });
     
   $(".trafficButton").on("click",function(){
	   var packId = $(this).attr("val");
       $('#myModel').modal({ remote: "#(base)/admin/order/traffic?packId="+packId });
   });
   
   
   $("#addPack").on("click",function(){
	   var orderId = $(this).attr("val");
       $('#myModel').modal({ remote: "#(base)/admin/order/addPack?id="+orderId });
   });
   
   $("#tab-3").on("click",".packdelete",function(){
	   var packId = $(this).attr("val");
	   $.ajax({
	        url: "deletePack",
	        type: "POST",
	        data: {"packId":packId},
	        dataType: "json",
	        cache: false,
	        success: function(response) {
	        	if (response.type == "success") {
	        		alert("操作成功");
	        		$("#packTr_"+packId).remove();
	            }else{
	                swal({title:'', text:response.msg,icon: 'error'});
	            }
	        }
	    });
   });
   
    
    $("#myModel").on("hidden.bs.modal", function() {
        $(this).removeData("bs.modal");
    });
    

});
</script>